/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoMltTest.go			*/
/********************************************************/

package main

import (
	"os"
	. "GoGlb"
	C "GoCls"
	N "GoNet"
)

func main() {
	if len(os.Args) > 1 {
		recv()
	} else {
		send()
	}
}

func recv() {
	i := 0
	m := new(N.GoUdp)
	if nil == m.GoUdpMulticast(N.GO_UP_UDPA, "238.1.10.128:12318") {
		for {
			r := make([]byte, GO_KBYTES1)
			_, e := m.GoUdpRecv(r)
			if nil == e {
				GoPrint("Count[%02d]: %s\n", i, string(r))
				i += 1
			} else {
				GoPrint("Failed to GoUdpRecv\n")
			}
		}
		m.GoUdpClose()
	} else {
		GoPrint("Failed to GoUdpListen\n")
	}
}

func send() {
	m := new(N.GoUdp)
	s := "Copyright (C) 2016 Gong Li Bin		"
	if nil == m.GoUdpDial(N.GO_UP_UDPA, "238.1.10.128:12318") {
		for i := 0; i < 10; i ++ {
			C.GoTimeSleep(1, 0)
			_, e := m.GoUdpWrite([]byte(s))
			if nil == e {
				GoPrint("Count[%02d]: %s\n", i, string(s))
			} else {
				GoPrint("Failure to GoUdpSend\n")
			}
		}
		m.GoUdpClose()
	} else {
		GoPrint("Failed to GoUdpDial\n")
	}
}
